<?php

class Auth extends MY_Controller { 
      function __construct()
     {
            
        parent::__construct();
        $this->load->helper('url');
        $this->load->helper('form'); 
        
        

     }
      
      public function login()
    {
         
        if ($_POST)
        {
            $user = User::validate_login($_POST['username'],$_POST['password']);
            if($user )
            {
                echo('$user :'.$user->username); 
                redirect('');
            } 
            else
            {
                $this->view_data['message']='Invalid username/password';
            }
        }
       // $field = $this->load->view('auth/login',$this->view_data,TRUE);
        
       // $this->load->view('layouts/application',array('yield' =>$field));
        
    }
    private function is_login()
    {
        if(!$this->user)
         {
             
             echo '<br/>Please log in first!<br/>';
             echo anchor(base_url().'auth/login','login');
             return false;
         }        
         return true;
    }
    public function test()
    {
        if(!$this->is_login()) die();
         echo '<br/>';
         
         echo anchor('auth/test3','Test3-mix layout/contentview');
         echo '<br/>';
         echo anchor('auth/test2','Test2-Admin layout');
         echo '<br/>';
        echo '<br/>';
     }
     public function test2()
     {
        if(!$this->is_login()) die();
         echo '<br/>';
         echo anchor('auth/test3','Test3-mix layout/contentview');
         echo '<br/>';
         echo anchor('auth/test','Test-Appliction layout');       
         echo '<br/>';
         $this->layout_view='admin';
     }
     public function test3()
     {
        if(!$this->is_login()) die();
         echo '<br/>';
         echo anchor('auth/test','Test-Appliction layout');
         echo '<br/>';
         echo anchor('auth/test2','Test2-Admin layout');
         echo '<br/>';
         echo '<br/>below demostrate admin layout with auth/test content view';
         $this->layout_view='admin';
         $this->content_view='auth/test';
         
     }
     
    public function logout()
    {
        User::logout();
        $this->login();
    }
}
?>